package com.cskaoyan.controller.admincontroller;

import com.cskaoyan.bean.po.MarketCoupon;
import com.cskaoyan.bean.po.MarketCouponUser;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.adminservice.CouponsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 小黑球
 * @datetime 2022/12/29 10:01
 * @description: TODO:
 */
@RestController
@RequestMapping("admin/coupon")
public class CouponsController {

    @Autowired
    CouponsService couponsService;

    /**
     * 优惠券管理的list方法
     *
     * @param info
     * @return
     */
    @RequestMapping("list")
    public BaseRespVo list(BasePageInfo info, String name, Short type, Short status) {
        CommonData<MarketCoupon> data = couponsService.list(info, name, type, status);
        return BaseRespVo.ok(data);
    }

    /**
     * 优惠券管理的添加方法
     *
     * @param marketCoupon
     * @return
     */
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody MarketCoupon marketCoupon) {
        MarketCoupon marketCoupon1 = couponsService.create(marketCoupon);
        return BaseRespVo.ok(marketCoupon1);
    }

    /**
     * 优惠券管理的编辑方法
     *
     * @param marketCoupon
     * @return
     */
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody MarketCoupon marketCoupon) {
        couponsService.update(marketCoupon);
        return BaseRespVo.ok();
    }

    /**
     * 优惠券管理的删除方法
     *
     * @param marketCoupon
     * @return
     */
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody MarketCoupon marketCoupon) {
        couponsService.delete(marketCoupon);
        return BaseRespVo.ok();
    }

    /**
     * 优惠券管理的详情页方法
     *
     * @param info
     * @param couponId
     * @param userId
     * @param status
     * @return
     */
    @RequestMapping("listuser")
    public BaseRespVo listuser(BasePageInfo info, Integer couponId, Integer userId, Short status) {
        CommonData<MarketCouponUser> data = couponsService.listuser(info, couponId, userId, status);
        return BaseRespVo.ok(data);
    }

    /**
     * 优惠券管理的详情页方法
     *
     * @param id
     * @return
     */
    @RequestMapping("read")
    public BaseRespVo read(Integer id) {
        MarketCoupon data = couponsService.read(id);
        return BaseRespVo.ok(data);
    }
}
